package com.itchu.common.utils;


import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.security.SecureRandom;

@Data
@Configuration
@ConfigurationProperties(prefix = "music.encoder.crypt")
public class PasswordConfig {

    private int strength;

    private String secret;

    @Bean
    public BCryptPasswordEncoder passwordEncoder() {
        //使用随机盐加密
        SecureRandom secureRandom = new SecureRandom(secret.getBytes());

        return new BCryptPasswordEncoder(strength, secureRandom);
    }       
}
